﻿#include "mainframeui.h"
#include "appinit.h"
#include <QApplication>
#include <QTextCodec>
#include <QFile>
#include <QSplashScreen>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
#if _MSC_VER
    QTextCodec *codec = QTextCodec::codecForName("gbk");
#else
    QTextCodec *codec = QTextCodec::codecForName("utf-8");
#endif
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForCStrings(codec);
    QTextCodec::setCodecForTr(codec);
#else
    QTextCodec *codec = QTextCodec::codecForName("utf-8");
    QTextCodec::setCodecForLocale(codec);
#endif

    //加载样式表  flatwhite.css psblack.css
    QFile file(":/qss/flatwhite.css");
    if (file.open(QFile::ReadOnly)) {
        QString qss = QLatin1String(file.readAll());
        QString paletteColor = qss.mid(20, 7);
        qApp->setPalette(QPalette(QColor(paletteColor)));
        qApp->setStyleSheet(qss);
        file.close();
    }

    a.setFont(QFont("Microsoft Yahei", 9));
    AppInit::Instance()->start();

    //加载并显示启动画面
    QSplashScreen splash(QPixmap(":\\image\\zwotech.png"));

    splash.setDisabled(true); //禁用用户的输入事件响应
//    splash.setFixedSize(200, 150);
    splash.show();

    splash.showMessage(QObject::tr("数据初始化中...."),
    Qt::AlignRight|Qt::AlignBottom,Qt::black);

    splash.showMessage(QObject::tr("串口初始化中...."),
    Qt::AlignRight|Qt::AlignBottom,Qt::black);

    MainFrameUi w;
    w.show();

    splash.finish(&w);
    return a.exec();
}
